//
//  WBHomeTableViewCell.swift
//  weibo
//
//  Created by 胡古古 on 2017/6/8.
//  Copyright © 2017年 hugugu. All rights reserved.
//

import UIKit
import SnapKit

class WBHomeTableViewCell: UITableViewCell {

    var toolbarTopConstraint:Constraint?
    
    var statusViewModel: WBStatusViewModel? {
        
        didSet {
         
            homeOrigina.statusViewModel = statusViewModel
            
            homeToolBar.statusViewModel = statusViewModel
            
            toolbarTopConstraint?.deactivate()
            
            if statusViewModel?.status?.retweeted_status != nil {
                // 显示微博视图
                homeRetWeet.isHidden = false
                
                homeToolBar.snp.makeConstraints({ (make) in
                    
                    toolbarTopConstraint = make.top.equalTo(homeRetWeet.snp.bottom).constraint
                })
                
                homeRetWeet.statusViewModel = statusViewModel

            } else {
                
                homeRetWeet.isHidden = true
                
                homeToolBar.snp.makeConstraints({ (make) in
                    
                    toolbarTopConstraint = make.top.equalTo(homeOrigina.snp.bottom).constraint
                })
            }
            
        }
        
    }
    
    
    fileprivate lazy var homeOrigina: WBHomeOrigina = WBHomeOrigina()
    fileprivate lazy var homeRetWeet: WBHomeRetweetView = WBHomeRetweetView()
    fileprivate lazy var homeToolBar: WBHomeToolBar = WBHomeToolBar()
  
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        
        contentView.backgroundColor = UIColor(white: 0.95, alpha: 1)
        
        contentView.addSubview(homeOrigina)
        homeOrigina.snp.makeConstraints { (make) in
            
            make.top.equalTo(contentView).offset(8)
            make.left.right.equalTo(contentView)
            
        }
        
        contentView.addSubview(homeRetWeet)
        homeRetWeet.snp.makeConstraints { (make) in
            
            make.top.equalTo(homeOrigina.snp.bottom)
            make.left.right.equalTo(homeOrigina)
        }
        
        contentView.addSubview(homeToolBar)
        homeToolBar.snp.makeConstraints { (make) in
            
           toolbarTopConstraint = make.top.equalTo(homeRetWeet.snp.bottom).constraint
            make.left.right.equalTo(contentView)
            make.bottom.equalTo(contentView)
            make.height.equalTo(35).priority(.high)
        }
        
    }
    
    
}
